package com.shenmazong.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shenmazong.pojo.TbTaskTheoryGradeDetail;
import com.shenmazong.service.TbTaskTheoryGradeDetailService;
import com.shenmazong.mapper.TbTaskTheoryGradeDetailMapper;
import com.shenmazong.utils.ResultResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 *
 */
@Service
public class TbTaskTheoryGradeDetailServiceImpl extends ServiceImpl<TbTaskTheoryGradeDetailMapper, TbTaskTheoryGradeDetail>
implements TbTaskTheoryGradeDetailService{

    @Autowired
    TbTaskTheoryGradeDetailMapper tbTaskTheoryGradeDetailMapper;

    @Override
    public PageInfo findTaskTheoryGradeDetailList(Integer pageNum, Integer pageSize, Object theoryGradeDetail) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbTaskTheoryGradeDetail> tbTaskTheoryGradeDetails=tbTaskTheoryGradeDetailMapper.findTaskTheoryGradeDetailList(theoryGradeDetail);
        PageInfo<TbTaskTheoryGradeDetail> pageInfo = new PageInfo<>(tbTaskTheoryGradeDetails);
        return pageInfo;
    }

    @Override
    public ResultResponse saveTaskTheoryGradeDetail(TbTaskTheoryGradeDetail tbTaskTheoryGradeDetail) {
        tbTaskTheoryGradeDetail.setCreateTime(new Date());
        tbTaskTheoryGradeDetail.setUpdateTime(new Date());
        int i = tbTaskTheoryGradeDetailMapper.insert(tbTaskTheoryGradeDetail);
        if(i<0){
            return ResultResponse.FAILED(-1,"添加失败");
        }
        return ResultResponse.SUCCESS("添加成功");
    }

    @Override
    public ResultResponse echoTaskTheoryGradeDetail(TbTaskTheoryGradeDetail tbTaskTheoryGradeDetail) {
        TbTaskTheoryGradeDetail gradeDetail = tbTaskTheoryGradeDetailMapper.selectById(tbTaskTheoryGradeDetail.getTheoryDetailId());
        if(gradeDetail==null){
            return ResultResponse.FAILED(-1,"回显失败");
        }
        return ResultResponse.SUCCESS(gradeDetail);
    }

    @Override
    public ResultResponse updateTaskTheoryGradeDetail(TbTaskTheoryGradeDetail tbTaskTheoryGradeDetail) {
        int i = tbTaskTheoryGradeDetailMapper.updateById(tbTaskTheoryGradeDetail);
        if(i<0){
            return ResultResponse.FAILED(-1,"修改失败");
        }
        return ResultResponse.SUCCESS("修改成功");
    }

    @Override
    public ResultResponse delTaskTheoryGradeDetail(TbTaskTheoryGradeDetail tbTaskTheoryGradeDetail) {
        tbTaskTheoryGradeDetailMapper.deleteById(tbTaskTheoryGradeDetail.getTheoryDetailId());
        return ResultResponse.SUCCESS("删除成功");
    }


}




